<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
    <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
    <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script>
    <script type="text/javascript">
        SyntaxHighlighter.defaults['toolbar'] = false;
        SyntaxHighlighter.all();
    </script>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>Debugging Struts</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="tutorials.html">Tutorials</a>&nbsp;&gt;&nbsp;<a href="getting-started.html">Getting Started</a>&nbsp;&gt;&nbsp;<a href="exception-handling.html">Exception Handling</a>&nbsp;&gt;&nbsp;<a href="debugging-struts.html">Debugging Struts</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">Debugging Struts</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=16941310">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=16941310">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=16941310">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=16941310">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=16941310">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=16941310">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent"><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The example code for this tutorial, debugging_struts, is available for checkout at <a shape="rect" class="external-link" href="https://github.com/apache/struts-examples" rel="nofollow">https://github.com/apache/struts-examples</a>.</p></div></div><h3 id="DebuggingStruts-Introduction">Introduction</h3><p>During development of a Struts 2 web application you may want to view the information being managed by the Struts 2 framework. This tutorial will cover two tools you can use to see how Struts 2 views your web application. One tool is the Struts 2 configuration plugin and the other is the debugging interceptor. This article also discusses how to set the log level to see more or fewer log messages.</p><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The Struts 2 <a shape="rect" class="external-link" href="http://struts.apache.org/mail.html">user mailing list</a> is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.</p></div></div><h3 id="DebuggingStruts-ConfigurationPlugin">Configuration Plugin</h3><p>The Struts 2 config browser plugin provides details about the configuration the Struts 2 framework is using to run your application. To use the plugin your application needs to have the struts2-config-browser-plugin-x.x.x.x.jar in your application's class path. The config-browser-plugin jar is part of the Struts 2 download and is also available in the Maven repository.</p><p>To use the plugin in your application, just call index.action in namespace config-browser. For example you could have the following link on your admin page (or just anywhere during your development).</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: html; gutter: false; theme: Default" style="font-size:12px;">&lt;a href="&lt;s:url action="index" namespace="config-browser" /&gt;"&gt;Launch the configuration browser&lt;/a&gt;
</pre>
</div></div><p>In the example application, there is a link to the configuration browser on the index.jsp page.</p><p>Clicking on the link for the configuration browser will cause the Struts 2 framework to return this page to your browser.<br clear="none"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="debugging-struts.data/debuging-struts-1.png"></span></p><p>You can click on an action link to see the configuration for that action. For example clicking on the register action link results in this.<br clear="none"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="debugging-struts.data/debuging-struts-2.png"></span></p><p>You may then click on one of the tabs (Results, Exception Mappings, Interceptors, Properties, Validators) to get more information about how the Struts 2 framework is has configured that specific action.</p><p>On the left side of the page is the config browser plugin menu. Clicking on constants will render a view that lists all the Struts 2 constants and their properties for your application. Clicking on beans shows the beans Struts 2 is managing. Clicking on Jars shows the jars your application is using.</p><h3 id="DebuggingStruts-UsingtheDebuggingInterceptor">Using the Debugging Interceptor</h3><p>If you have set <code>devMode</code> to true (in the example application see struts.xml) then one of the interceptors that is activated when Struts 2 processes an action is the DebuggingInterceptor. The DebuggingInterceptor looks for a query string appended to the action URL with a name of debug and a value of xml, console, command, or browser.</p><p>If the DebuggingInterceptor finds that query string then it will halt further execution of the action and instead return to the browser debugging information. The format of the returned information depends on the value of the debug query parameter. See <a shape="rect" href="debugginginterceptor.html">DebuggingInterceptor</a> for more detail.</p><p>In the example application on the index.jsp is a link for displaying debugging information. This link includes the query string debug=browser. If you click on this link you'll see a table with columns that can be expanded and collapsed. The table contains the various objects and their state being managed by the Struts 2 framework.<br clear="none"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="debugging-struts.data/debuging-struts-3.png"></span></p><p>Note that to enable the correct display and interaction of the expand/collapse links on the debugging information web page you need to include the s:head tag in your JSP's head section (see index.jsp in the example application) and also include the Struts 2 dojo plugin in your application's class path. The Struts 2 dojo plugin is available as part of the Struts 2 download and from the Maven repository.</p><h3 id="DebuggingStruts-Struts2Logging">Struts 2 Logging</h3><p>The Struts 2 framework will write to a log a great deal of information if you've configured the log properties to log at the debug level. In the example application, view log4j.xml. The two major packages involved in the Struts 2 framework, com.opensymphony and org.apache.struts2, are configured to write debug and above log messages. When you run the application view the standard out for your Servlet container to see all the information written to the log. Please check <a shape="rect" href="logging.html">Logging</a> page for other options.</p><h3 id="DebuggingStruts-Summary">Summary</h3><p>Using the configuration browser plugin and the debugging interceptor can assist you in trouble shooting a problem with a Struts 2 web application. These tools should only be used in development.</p><p>Prior to creating your war file for deployment to production you should change devmode to false and remove the debugging links. You may also want to adjust the level of logging in your log properties file to a higher level (info or warn) to reduce the number of log messages.</p><h3 id="DebuggingStruts-UpNext">Up Next</h3><p>In our next tutorial we'll cover how to use additional Struts 2 form tags.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Next</p></th><td colspan="1" rowspan="1" class="confluenceTd"><p>Onward to <a shape="rect" href="struts-2-form-tags.html">Struts 2 Form Tags</a></p></td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Prev</p></th><td colspan="1" rowspan="1" class="confluenceTd"><p>Return to <a shape="rect" href="exception-handling.html">Exception Handling</a></p></td></tr></tbody></table></div></div>
        </div>

        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
